﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;
using System.Runtime.Serialization;

namespace ClientApplication
{
    [Serializable]
    public class Contestant
    {
        /// <summary>
        /// Medlemsdata för en tävlande, 'get' sätt som publik och 'set' som privat
        /// </summary>
        /// 
        public int id { get; set; }
        public string name { get; set; }
        public int age { get; set; }
        public List<Jump> jumps { get; set; }
        public int sex { get; set; } //0 = male, 1 = female
        public string nationality { get; set; }
        public double totalScore { get; set; }
        //Keep track of the number of jumps this diver have performed.
        public int jump { get; set; }

        public Contestant()
        {
            this.jump = 1;
            this.id = 0;
            this.name = "";
            this.age = 0;
            this.sex = 0;
            this.nationality = "";
            this.jumps = new List<Jump>();
            this.totalScore = 0;
        }

        public Contestant(int id, string name, int age, int sex, string nationality, double totalScore = 0, int jump = 1)
        {
            this.jump = jump;
            this.id = id;
            this.name = name;
            this.age = age;
            this.sex = sex; 
            this.nationality = nationality;
            this.jumps = new List<Jump>();
            this.totalScore = totalScore;
        }

        public Contestant(Contestant toCopy)
        {
            jump = toCopy.jump;
            id = toCopy.id;
            name = toCopy.name;
            age = toCopy.age;
            sex = toCopy.sex;
            nationality = toCopy.nationality;
            jumps = toCopy.jumps;
            totalScore = toCopy.totalScore;
        }

        public void AddJump(string typeOfJump, List<Score> allJudgesScores, double height, double difficulty)
        {
            Jump temp = new Jump(typeOfJump, allJudgesScores, height, difficulty);
            jumps.Add(temp);
            jump++;
            CalculateTotalScore();
        }

        private void CalculateTotalScore()
        {
            double tempScore = 0;
            for (int i = 0; i < jumps.Count; i++)
            {
                tempScore += jumps[i].totalScore;
            }
            this.totalScore = tempScore;
        }
    }
}
